package com.nineclock.attendance.controller;

import com.nineclock.attendance.dto.AttendGroupDTO;
import com.nineclock.attendance.dto.AttendPunchDTO;
import com.nineclock.attendance.dto.AttendPunchUserWholeDayDTO;
import com.nineclock.attendance.service.AttendGroupService;
import com.nineclock.attendance.service.AttendPunchService;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@Api(value = "考勤组管理接口", tags = "考勤服务")
public class AttendGroupController {
    @Autowired
    private AttendGroupService attendGroupService;
    @Autowired
    private AttendPunchService attendPunchService;

    /**
     * 考勤组: 分页查询
     * 接口路径：GET/atte/attendGroup
     */
    @ApiOperation("考勤组: 分页查询")
    @GetMapping("attendGroup")
    public Result<PageResult<AttendGroupDTO>> getAttendGroupPage(@RequestParam(defaultValue = "1") Integer page,
                                                                 @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResult<AttendGroupDTO> pageResult = attendGroupService.getAttendGroupPage(page, pageSize);
        return Result.success(pageResult);
    }

    /**
     * 考勤组: 添加
     * 接口路径：POST/atte/attendGroup
     */
    @ApiOperation("考勤组: 添加")
    @PostMapping("attendGroup")
    public Result insertAttendGroup(@RequestBody AttendGroupDTO attendGroupDTO) {
        attendGroupService.insertAttendGroup(attendGroupDTO);
        return Result.success();
    }

    /**
     * 考勤组: 获取当前登录用户考勤组
     * 接口路径：GET/atte/getAttendGroupByUserId
     */
    @ApiOperation("考勤组: 获取当前登录用户考勤组")
    @GetMapping("getAttendGroupByUserId")
    public Result<AttendGroupDTO> getAttendGroupByUserId() {
        AttendGroupDTO attendGroupDTO = attendGroupService.getAttendGroupByUserId();
        return Result.success(attendGroupDTO);
    }

    /**
     * 考勤: 移动端打卡
     * 接口路径：POST/atte/punch
     */
    @ApiOperation("考勤: 移动端打卡")
    @PostMapping("punch")
    public Result punch(@RequestBody AttendPunchDTO attendPunchDTO) {
        attendPunchService.punch(attendPunchDTO);
        return Result.success();
    }
    /**
     * 考勤: 查询打卡数据
     * 接口路径：GET/atte/get
     */
    @ApiOperation("考勤: 查询打卡数据")
    @GetMapping("get")
    public Result<AttendPunchUserWholeDayDTO> get(){
        AttendPunchUserWholeDayDTO attendPunchUserWholeDayDTO = attendPunchService.get();
        return Result.success(attendPunchUserWholeDayDTO);
    }
    /**
     * 考勤: 查询考勤列表数据
     * 接口路径：GET/atte/members
     */
    @ApiOperation("考勤: 查询考勤列表数据")
    @GetMapping("members")
    public Result<List<AttendPunchDTO>> members(@RequestParam String startTime,
                                          @RequestParam String endTime){
        List<AttendPunchDTO> attendPunchDTOList = attendPunchService.members(startTime,endTime);
        return Result.success(attendPunchDTOList);
    }
    /**
     * 考勤: 导出考勤列表数据
     * 接口路径：GET/atte/export
     */
    @ApiOperation("考勤: 导出考勤列表数据")
    @GetMapping("export")
    public void exportAttendData(String startTime, String endTime) throws IOException {
        attendPunchService.exportAttendData(startTime, endTime);
    }
}
